Unit BControllerGeneratorUnit;

{$mode objfpc}{$H+}

Interface

Uses
  Classes, SysUtils, strutils, BListsUnit, BCommonUnit, BPeaUnit, BGeneratorUnit;

Type

{ BControllerGeneratorClass }

 BControllerGeneratorClass = Class(BGeneratorClass)
  Private
    Procedure UpdateUses;
    Procedure UpdatePrivate;
    Procedure UpdateConsts;
    Procedure UpdateEnumsMethods;
    Procedure UpdateGetInfoMethod;
    Procedure UpdateUpdateMethod;
    Procedure UpdateParsePlain;
    Procedure UpdateParsePlural;
    Procedure UpdatePlainMethods;
    Procedure UpdateGetJSON;

    Procedure UpdatePeasPluralMethods;
    Procedure UpdateHoldersPluralMethods;
    Procedure UpdatePluralMethods;
  Public
    Procedure Update; override;
    Procedure SavePeaUnit; override;
    Constructor Build(Const aPeaPath: String; Const aPea: BPeaClass;
      Const aProjectName: String);
End;

Implementation

Uses
  BControllerCodePartsUnit;

ResourceString
  rsControllersDir = 'Controllers/';
  mskPeaControllerUnit = 'b%scontrollerunit.pas';
  rsPlainMethodsDeclare = 'PlainMethodsDeclare';
  rsPlainMethods = 'PlainMethods';
  rsPlainGetInfoVars = 'PlainGetInfoVars';
  rsPlainGetInfo = 'PlainGetInfo';
  rsPlainUpdateVars = 'PlainUpdateVars';
  rsPlainUpdate = 'PlainUpdate';
  rsPluralMethodsDeclare = 'PluralMethodsDeclare';
  rsPluralMethods = 'PluralMethods';
  mskGetPlain = 'Var a%s: %s; ';
  mskGetPea = 'Var a%sID: %s; ';
  mskUpPlain = 'Const a%s: %s; ';
  mskUpPea = 'Const a%sID: %s; ';
  rsGetJSON = 'GetJSON';

  {$define ppkPlainPlural :=
    ppkStrings,
    ppkIntegers,
    ppkDoubles,
    ppkDateTimes,
    ppkBooleans
  }

  {$define ppkPlain :=
    ppkString,
    ppkInteger,
    ppkDouble,
    ppkDate,
    ppkDateTime,
    ppkTime,
    ppkBoolean
  }

{ BControllerGeneratorClass }

Procedure BControllerGeneratorClass.UpdateUses;
Var
  aString: String;
  i, aIndex: Integer;
  aBuffer: BStringsList;
Begin
  aBuffer := BStringsList.Build;
  If Pea.Kind = pkHolder Then
    Begin
      aString := Format('B%sUnit', [Pea.HoldingPea.Caption]);
      If aBuffer.IndexOf(aString) = -1 Then aBuffer.Add(aString);
    End;

  For i := 0 To Pea.Properties.Count - 1 Do
    Begin
      Case Pea[i].Kind Of
        ppkPea, ppkPeas, ppkHolders:
          Begin
            aString := Format('B%sControllerUnit', [Pea[i].Pea.PluralCaption]);
            If aBuffer.IndexOf(aString) = -1 Then
              aBuffer.Add(aString);
            aString := Format('B%sUnit', [Pea[i].Pea.Caption]);
          End;
        Else
          aString := '';
      End;
      If Not(aString = '') And (aBuffer.IndexOf(aString) = -1) Then
        aBuffer.Add(aString);
    End;
  aString := '';
  For i := 0 To aBuffer.Count - 1 Do
    aString += ', ' + aBuffer[i];
  aIndex := ClearSection('Uses');
  AddLine(aString, 2, aIndex);
  aBuffer.Burn;
End;

Procedure BControllerGeneratorClass.UpdatePrivate;
Var
  aIndex: Integer;
Begin
  aIndex := ClearSection('Private');
  AddLine('bManager: B%sManagerClass;',[Pea.HoldingPea.PluralCaption],6,aIndex);
End;

Procedure BControllerGeneratorClass.UpdateConsts;
Begin

End;

Procedure BControllerGeneratorClass.UpdateEnumsMethods;
Begin

End;

Procedure BControllerGeneratorClass.UpdateGetInfoMethod;
Var
  i, aIndex: Integer;
  aBuffer: BStringsList;
Begin
  aBuffer := BStringsList.Build;
  aIndex := ClearSection(rsPlainGetInfo);
  For i := 0 To Pea.Properties.Count - 1 Do
    Case Pea[i].Kind Of
      ppkPlain:
        AddLine('a%1:s := a%0:s.%1:s;', [Pea.Caption, Pea[i].Caption],2,aIndex);
      ppkPea:
        Begin
          AddLine('If a%0:s.%1:s = nil Then',
            [Pea.Caption, Pea[i].Caption], 2, aIndex);
          AddLine('a%0:sID := -1', [Pea[i].Caption], 4, aIndex);
          AddElse(2, aIndex);
          AddLine('a%1:sID := a%0:s.%1:s.ID;',
            [Pea.Caption, Pea[i].Caption], 4, aIndex);
        End;
    End;
End;

Procedure BControllerGeneratorClass.UpdateUpdateMethod;
Var
  aIndex: Integer;
  i: Integer;
  aBuffer: BStringsList;
Begin
  aBuffer := BStringsList.Build;
  aIndex := ClearSection(rsPlainUpdateVars);
  For i := 0 To Pea.Properties.Count - 1 Do
    If Pea[i].Kind = ppkPea Then
      If aBuffer.IndexOf(Pea[i].Pea.Caption) = -1 Then
        Begin
          aBuffer.Add(Pea[i].Pea.Caption);
          AddLine('a%s: %s;',
            [Pea[i].Pea.Caption, Pea[i].KindUnlocked], 2, aIndex);
          AddLine('a%0:sManager: B%0:sManagerClass;',
            [Pea[i].Pea.PluralCaption], 2, aIndex);
        End;
  aBuffer.Burn;
  aIndex := ClearSection(rsPlainUpdate);
  For i := 0 To Pea.Properties.Count - 1 Do
    Case Pea[i].Kind Of
      ppkPlain:
        AddLine('a%0:s.%1:s := a%1:s;', [Pea.Caption, Pea[i].Caption],2,aIndex);
      ppkPea:
        Begin
          AddLine('a%1:s := a%2:sManager.GetObject(a%0:sID);', [Pea[i].Caption,
            Pea[i].Pea.Caption, Pea[i].Pea.PluralCaption], 2, aIndex);
          AddLine('a%0:s.%1:s := a%1:s;', [Pea.Caption, Pea[i].Caption,
            Pea[i].Pea.Caption], 2, aIndex);
        End;
    End;
End;

Procedure BControllerGeneratorClass.UpdateParsePlain;
Var
  i, aIndex: Integer;
  Procedure BuildParsePlainVars;
  Var
    i: Integer;
    aBuffer: BStringsList;
  Begin
    aBuffer := BStringsList.Build;
    aIndex := ClearSection('ParsePlainVars');
    If Pea.Kind = pkHolder Then
      AddLine('a%0:s: B%0:sClass;', [Pea.HoldingPea.Caption], 2, aIndex);
    For i := 0 To Pea.Properties.Count - 1 Do
      Case Pea[i].Kind Of
        ppkPlain:
          AddLine('a%s: %s;', [Pea[i].Caption, Pea[i].KindUnlocked], 2, aIndex);
        ppkPlainPlural:
          AddLine('a%s: %s = nil;',
            [Pea[i].PluralCaption, Pea[i].KindUnlocked], 2, aIndex);
        ppkPea:
          If Not(Pea[i].Kind = ppkHolders) And
            (aBuffer.IndexOf(Pea[i].Pea.Caption) = -1) Then
            Begin
              aBuffer.Add(Pea[i].Pea.Caption);
              AddLine('a%0:s: B%0:sClass = nil;', [Pea[i].Pea.Caption], 2, aIndex);
              AddLine('a%0:sManager: B%0:sManagerClass = nil;',
                [Pea[i].Pea.PluralCaption], 2, aIndex);
            End;
        ppkPeas, ppkHolders:
          If aBuffer.IndexOf(Pea[i].Pea.PluralCaption) = -1 Then
            Begin
              aBuffer.Add(Pea[i].Pea.PluralCaption);
              AddLine('a%s: %s = nil;',
                [Pea[i].Pea.PluralCaption, Pea[i].KindUnlocked], 2, aIndex);
            End;
      End;
    aBuffer.Burn;
  End;
  Procedure InitializeObjects;
  Var
    i: Integer;
    aBuffer: BStringsList;
  Begin
    aBuffer := BStringsList.Build;
    For i := 0 To Pea.Properties.Count - 1 Do
      Case Pea[i].Kind Of
        ppkPlainPlural:
          AddLine('a%s := %s.Build;',
            [Pea[i].PluralCaption, Pea[i].KindUnlocked], 4, aIndex);
        ppkPea:
          If Not(Pea[i].Kind = ppkHolders) And
            (aBuffer.IndexOf(Pea[i].Pea.Caption) = -1) Then
            Begin
              aBuffer.Add(Pea[i].Pea.Caption);
              AddLine('a%0:sManager := B%0:sManagerClass.Build;',
                [Pea[i].Pea.PluralCaption], 4, aIndex);
            End;
        ppkPeas, ppkHolders:
          If aBuffer.IndexOf(Pea[i].Pea.PluralCaption) = -1 Then
            Begin
              aBuffer.Add(Pea[i].Pea.PluralCaption);
              AddLine('a%s := %s.Build;',
                [Pea[i].Pea.PluralCaption, Pea[i].KindUnlocked], 4, aIndex);
            End;
      End;
    aBuffer.Burn;
    AddEmptyLine(aIndex);
  End;
  Procedure FinalizeObjects;
  Var
    i: Integer;
    aBuffer: BStringsList;
  Begin
    aBuffer := BStringsList.Build;
    For i := 0 To Pea.Properties.Count - 1 Do
      Case Pea[i].Kind Of
        ppkPlainPlural:
          AddLine('a%s.Burn;', [Pea[i].PluralCaption], 4, aIndex);
        ppkPea:
          If aBuffer.IndexOf(Pea[i].Pea.Caption) = -1 Then
            Begin
              aBuffer.Add(Pea[i].Pea.Caption);
              AddLine('a%0:sManager.Burn;',
                [Pea[i].Pea.PluralCaption], 4, aIndex);
            End;
        ppkPeas, ppkHolders:
          If aBuffer.IndexOf(Pea[i].Pea.PluralCaption) = -1 Then
            Begin
              aBuffer.Add(Pea[i].Pea.PluralCaption);
              AddLine('a%s.Burn;',
                [Pea[i].Pea.PluralCaption], 4, aIndex);
            End;
      End;
    aBuffer.Burn;
  End;
  Procedure BuildPluralProcessors;
  Var
    i: Integer;
    aBuffer: BStringsList;
  Begin
    aBuffer := BStringsList.Build;
    For i := 0 To Pea.Properties.Count - 1 Do
      If aBuffer.IndexOf(Pea[i].Pea.Caption) = -1 Then
        Begin
          aBuffer.Add(Pea[i].Pea.Caption);
          Case Pea[i].Kind Of
            ppkPeas:
              AddLines(CODE_PLURAL_PEAS_PARSE,
                [Pea.Caption, Pea[i].Pea.PluralCaption], aIndex);
            ppkHolders:
              AddLines(CODE_PLURAL_HOLDERS_PARSE,
                [Pea[i].Pea.PluralCaption], aIndex);
          End;
        End;
    aBuffer.Burn;
  End;

Begin
  // Создаём переменные
  BuildParsePlainVars;


  // Иницилизируем списки и контроллеры
  aIndex := ClearSection('InitializeParseObjects');
  InitializeObjects;

  aIndex := ClearSection('ProcessPluralProperties');
  BuildPluralProcessors;

  aIndex := ClearSection('ParsePlain');
  // Парсим и обрабатываем строку
  For i := 0 To Pea.Properties.Count - 1 Do
    Case Pea[i].Kind Of
      ppkPlain:
        Begin
          AddLine('GetJSItem(a%0:sString, rs%1:s, a%1:s);',
            [Pea.Caption, Pea[i].Caption], 4, aIndex);
          AddLine('a%0:s.%1:s := a%1:s;',[Pea.Caption,Pea[i].Caption],4,aIndex);
        End;
      ppkPlainPlural:
        Begin
          AddEmptyLine(aIndex);
          AddLine('aBuffer := GetJSArr(a%0:sString, rs%1:s, %2:s);',
            [{0}Pea.Caption, {1}Pea[i].PluralCaption, {2}Pea[i].KindUnlocked],
            4, aIndex);
          AddLine('Fill%0:s(aBuffer, a%1:s);',
            [Pea[i].KindUnlocked, Pea[i].PluralCaption], 4, aIndex);
          AddLine('a%0:s.Load%1:s(a%1:s);',
            [Pea.Caption, Pea[i].PluralCaption], 4, aIndex);
        End;
      ppkPea:
        Begin
          AddEmptyLine(aIndex);
          AddLine('GetJSItem(a%0:sString, rs%1:s, aID);',
            [Pea.Caption, Pea[i].Caption], 4, aIndex);
          AddLine('a%0:s := a%1:sManager.GetObject(aID);',
            [Pea[i].Pea.Caption, Pea[i].Pea.PluralCaption], 4, aIndex);
          AddLine('a%0:s.%1:s := a%2:s;',
            [Pea.Caption, Pea[i].Caption, Pea[i].Pea.Caption], 4, aIndex);
        End;
      ppkPeas, ppkHolders:
        Begin
          AddEmptyLine(aIndex);
          AddLine('If Process%0:s(rs%1:s, a%0:s) Then',
            [Pea[i].Pea.PluralCaption, Pea[i].PluralCaption], 4, aIndex);
          AddLine('a%0:s.Load%1:s(a%2:s);',
            [Pea.Caption, Pea[i].PluralCaption, Pea[i].Pea.PluralCaption],
            6, aIndex);
        End;
    End;

  aIndex := ClearSection('FinalizeParseObjects');
  FinalizeObjects;
End;

Procedure BControllerGeneratorClass.UpdateParsePlural;
Begin

End;

Procedure BControllerGeneratorClass.UpdatePlainMethods;
Var
  i, aIndex: Integer;
  aGetParams, aUpdateParams: String;
Begin
  If Pea.Kind = pkHolder Then Exit;

  aGetParams := Format('Const a%0:sID: Integer; ', [Pea.Caption]);
  aUpdateParams := Format('Const a%0:sID: Integer; ', [Pea.Caption]);
  For i := 0 To Pea.Properties.Count - 1 Do
    If Not(Pea[i].IsPlural) Then
      Begin
        aGetParams += Format(IfThen(Pea[i].Kind=ppkPea, mskGetPea, mskGetPlain),
          [Pea[i].Caption, Pea[i].KindCtrl]);
        aUpdateParams+=Format(IfThen(Pea[i].Kind=ppkPea, mskUpPea, mskUpPlain),
          [Pea[i].Caption, Pea[i].KindCtrl]);
      End;
  aGetParams += 'Var aErrorInfo: BErrorInfoRec';
  aUpdateParams += 'Var aErrorInfo: BErrorInfoRec';

  aIndex := ClearSection(rsPlainMethodsDeclare);
  AddLine('Procedure Get%sInfo(%s);', [Pea.Caption, aGetParams], 6, aIndex);
  AddLine('Procedure Update%s(%s);', [Pea.Caption, aUpdateParams], 6, aIndex);

  aIndex := ClearSection(rsPlainMethods);
  AddLines(CODE_PLAIN_GET_INFO,
    [Pea.Caption, Pea.PluralCaption, aGetParams], aIndex);
  AddLines(CODE_PLAIN_UPDATE,
    [Pea.Caption, Pea.PluralCaption, aUpdateParams], aIndex);
  UpdateGetInfoMethod;
  UpdateUpdateMethod;
End;

Procedure BControllerGeneratorClass.UpdateGetJSON;
Var
  i, aIndex: Integer;
Begin
  aIndex := ClearSection(rsGetJSON);
  For i := 0 To Pea.Properties.Count - 1 Do
    Case Pea[i].Kind Of
      ppkPlain:
        AddLine('AddJSItem(Result, rs%1:s, a%0:s.%1:s);',
          [Pea.Caption, Pea[i].Caption], 2, aIndex);
      ppkPea:
        Begin
          AddLine('If a%0:s.%1:s = nil Then',
            [Pea.Caption, Pea[i].Caption], 2, aIndex);
          AddLine('AddJSItem(Result, rs%1:s, -1)',
            [Pea.Caption, Pea[i].Caption], 4, aIndex);
          AddElse(2, aIndex);
          AddLine('AddJSItem(Result, rs%1:s, a%0:s.%1:s.ID);',
            [Pea.Caption, Pea[i].Caption], 4, aIndex);
        End;
    End;
End;

Procedure BControllerGeneratorClass.UpdatePeasPluralMethods;
  Function GetPlainMask(Const aProperty: BPeaPropertyClass): String;
  Begin
    Result := '';
    Case aProperty.Kind Of
      ppkStrings: Result := '"%s"';
      ppkIntegers: Result := '%d';
      ppkDoubles: Result := '%f';
      //TODO: check Date
      ppkDateTimes: Result := '"%s"';
    End;
  End;
  Function GetPlainResult(Const aProperty: BPeaPropertyClass): String;
  Begin
    Result := '';
    Case aProperty.Kind Of
      ppkStrings, ppkIntegers, ppkDoubles: Result := 'Items[i]';
      ppkDateTimes: Result := 'FormatDateTime(''dd.mm.yyyy'', Items[i])';
    End;
  End;
Var
  i, aIndex: Integer;
Begin
  aIndex := ClearSection(rsPluralMethodsDeclare);
  For i := 0 To Pea.Properties.Count - 1 Do
    If Pea[i].IsPlural Then
      Begin
        AddLine('Function Get%0:s%2:s(Const a%0:sID: Integer; ' +
          'Const aCallback: String; Var aErrorInfo: BErrorInfoRec): String;',
          [Pea.Caption, '', Pea[i].PluralCaption], 6, aIndex);
        AddLine('Procedure Get%0:s%2:s(Const a%0:sID: Integer; ' +
          'Const aCallback: String; Var a%2:sString: String; ' +
          'Var aErrorInfo: BErrorInfoRec);',
          [Pea.Caption, '', Pea[i].PluralCaption], 6, aIndex);
        AddLine('Procedure Update%0:s%2:s(Const a%0:sID: Integer; ' +
          'Const a%2:sString: String; Var aErrorInfo: BErrorInfoRec);',
          [Pea.Caption, '', Pea[i].PluralCaption], 6, aIndex);
      End;

  aIndex := ClearSection(rsPluralMethods);
  For i := 0 To Pea.Properties.Count - 1 Do
    Case Pea[i].Kind Of
      ppkPlainPlural:
        Begin
          AddLines(CODE_PEA_PLURAL_PLAIN_UPDATE,
            [{0}Pea.Caption, {1}Pea.PluralCaption, {2}Pea[i].PluralCaption,
            {3}Pea[i].KindUnlocked], aIndex);
          AddLines(CODE_PEA_PLURAL_PLAIN_GET,
            [{0}Pea.Caption, {1}Pea.PluralCaption, {2}Pea[i].PluralCaption,
            {3}GetPlainMask(Pea[i]), {4}GetPlainResult(Pea[i])], aIndex);
        End;
      ppkPeas:
        Begin
          AddLines(CODE_PEA_PLURAL_PEAS_GET,
            [{0}Pea.Caption, {1}Pea.PluralCaption, {2}Pea[i].PluralCaption,
            {3}Pea[i].Pea.Caption, {4}Pea[i].Pea.PluralCaption], aIndex);
          AddLines(CODE_PEA_PLURAL_PEAS_UPDATE,
            [{0}Pea.Caption, {1}Pea.PluralCaption, {2}Pea[i].PluralCaption,
            {3}Pea[i].Pea.Caption, {4}Pea[i].Pea.PluralCaption], aIndex);
        End;
      ppkHolders:
        Begin
          AddLines(CODE_PEA_PLURAL_HOLDERS_GET,
            [{0}Pea.Caption, {1}Pea.PluralCaption, {2}Pea[i].PluralCaption,
            {3}Pea[i].Pea.Caption, {4}Pea[i].Pea.PluralCaption], aIndex);
          AddLines(CODE_PEA_PLURAL_HOLDERS_UPDATE,
            [{0}Pea.Caption, {1}Pea.PluralCaption, {2}Pea[i].PluralCaption,
            {3}Pea[i].Pea.Caption, {4}Pea[i].Pea.PluralCaption], aIndex);
        End;
    End;
End;

Procedure BControllerGeneratorClass.UpdateHoldersPluralMethods;
  Function GetPlainMask(Const aProperty: BPeaPropertyClass): String;
  Begin
    Result := '';
    Case aProperty.Kind Of
      ppkStrings: Result := '"%s"';
      ppkIntegers: Result := '%d';
      ppkDoubles: Result := '%f';
      //TODO: check Date
      ppkDateTimes: Result := '"%s"';
    End;
  End;
  Function GetPlainResult(Const aProperty: BPeaPropertyClass): String;
  Begin
    Result := '';
    Case aProperty.Kind Of
      ppkStrings, ppkIntegers, ppkDoubles: Result := 'Items[i]';
      ppkDateTimes: Result := 'FormatDateTime(''dd.mm.yyyy'', Items[i])';
    End;
  End;
Var
  i, aIndex: Integer;
Begin
  aIndex := ClearSection(rsPluralMethodsDeclare);
  For i := 0 To Pea.Properties.Count - 1 Do
    If Pea[i].IsPlural Then
      Begin
        AddLine('Function Get%0:s%2:s(Const aOwner: B%1:sOwnerClass; ' +
          'Const a%0:sID: Integer; Const aCallback: String; ' +
          'Var aErrorInfo: BErrorInfoRec): String;',
          [Pea.Caption, Pea.PluralCaption, Pea[i].PluralCaption], 6, aIndex);
        AddLine('Procedure Get%0:s%2:s(Const aOwner: B%1:sOwnerClass; ' +
          'Const a%0:sID: Integer; Const aCallback: String; ' +
          'Var a%2:sString: String; Var aErrorInfo: BErrorInfoRec);',
          [Pea.Caption, Pea.PluralCaption, Pea[i].PluralCaption], 6, aIndex);
        AddLine('Procedure Update%0:s%2:s(Const aOwner: B%1:sOwnerClass; ' +
          'Const a%0:sID: Integer; Const a%2:sString: String; ' +
          'Var aErrorInfo: BErrorInfoRec);',
          [Pea.Caption, Pea.PluralCaption, Pea[i].PluralCaption], 6, aIndex);
      End;

  aIndex := ClearSection(rsPluralMethods);
  For i := 0 To Pea.Properties.Count - 1 Do
    Case Pea[i].Kind Of
      ppkPlainPlural:
        Begin
          AddLines(CODE_HOLDER_PLURAL_PLAIN_UPDATE,
            [{0}Pea.Caption, {1}Pea.PluralCaption, {2}Pea[i].PluralCaption,
            {3}Pea[i].KindUnlocked], aIndex);
          AddLines(CODE_HOLDER_PLURAL_PLAIN_GET,
            [{0}Pea.Caption, {1}Pea.PluralCaption, {2}Pea[i].PluralCaption,
            {3}GetPlainMask(Pea[i]), {4}GetPlainResult(Pea[i])], aIndex);
        End;
      ppkPeas:
        Begin
          AddLines(CODE_HOLDER_PLURAL_PEAS_GET,
            [{0}Pea.Caption, {1}Pea.PluralCaption, {2}Pea[i].PluralCaption,
            {3}Pea[i].Pea.Caption, {4}Pea[i].Pea.PluralCaption], aIndex);
          AddLines(CODE_HOLDER_PLURAL_PEAS_UPDATE,
            [{0}Pea.Caption, {1}Pea.PluralCaption, {2}Pea[i].PluralCaption,
            {3}Pea[i].Pea.Caption, {4}Pea[i].Pea.PluralCaption], aIndex);
        End;
      ppkHolders:
        Begin
          AddLines(CODE_HOLDER_PLURAL_HOLDERS_GET,
            [{0}Pea.Caption, {1}Pea.PluralCaption, {2}Pea[i].PluralCaption,
            {3}Pea[i].Pea.Caption, {4}Pea[i].Pea.PluralCaption], aIndex);
          AddLines(CODE_HOLDER_PLURAL_HOLDERS_UPDATE,
            [{0}Pea.Caption, {1}Pea.PluralCaption, {2}Pea[i].PluralCaption,
            {3}Pea[i].Pea.Caption, {4}Pea[i].Pea.PluralCaption], aIndex);
        End;
    End;
End;

Procedure BControllerGeneratorClass.UpdatePluralMethods;
Begin
  Case Pea.Kind Of
    pkPlain, pkTree: UpdatePeasPluralMethods;
    pkHolder: UpdateHoldersPluralMethods;
  End;
End;

Procedure BControllerGeneratorClass.Update;
Begin
  UpdateUses;
  UpdatePrivate;
  UpdateConsts;
  UpdateEnumsMethods;
  UpdatePlainMethods;
  UpdatePluralMethods;
  UpdateParsePlain;
  UpdateParsePlural;
  UpdateGetJSON;
End;

Procedure BControllerGeneratorClass.SavePeaUnit;
Begin
  bUnitFile.SaveToFile(bPeasPath + rsControllersDir +
    LowerCase(Format(mskPeaControllerUnit, [Pea.PluralCaption])));
End;

Constructor BControllerGeneratorClass.Build(Const aPeaPath: String;
  Const aPea: BPeaClass; Const aProjectName: String);
Var
  aPeaModelUnit: String;
Begin
  Inherited Build(aPeaPath, aProjectName);;
  bPea := aPea;

  aPeaModelUnit := bPeasPath + rsControllersDir +
    LowerCase(Format(mskPeaControllerUnit, [Pea.PluralCaption]));
  If FileExists(aPeaModelUnit) Then
    bUnitFile.LoadFromFile(aPeaModelUnit)
  Else
    InitializeUnitFile(fkController);
End;

End.

